<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        /* 
            需求：计算两个时间相差多久
                例如：2022-09-20 与当前时间相差多久
        */

        function dateDiff(dateTime){
           var currentTimt =  Date.now()
           var inputTime = Date.parse(dateTime)
           //计算时间差
           var seconds = (inputTime-currentTimt)/1000
           //把秒转换为天
           var day = parseInt(seconds / 60 /60 /24);
           //把秒转换为小时
           var hour=parseInt(seconds / 60 /60 %24)
           //转换为分钟
           var minutes = parseInt(seconds/60 % 60)
           //转换为秒
           var seconds = parseInt(seconds % 60)

           console.log("当前时间相差"+day+"天"+hour+"小时"+day+"天"+minutes+"分钟"+seconds+"秒")
        }
        dateDiff('2023-11-30 18:00:00')
    </script>
</head>
<body>
    
</body>
</html>